
import time
import socketserver
class Myserver(socketserver.BaseRequestHandler):
    def handle(self):
        #print(self.request)#self.request就是conn
        conn=self.request
        while True:
            try:
                content=conn.recv(1024).decode('utf-8')
                conn.send(content.upper().encode('utf-8'))
                time.sleep(0.5)
            except ConnectionResetError:
                break


servers=socketserver.ThreadingTCPServer(('127.0.0.1',9001),Myserver)
servers.serve_forever()#一直提供服务








#并发的tcp协议server端
class Myserver(socketserver.BaseRequestHandler):
    def handle(self):
        conn=self.request
        while True:
            try:
                content=conn.recv(1024).decode('utf-8')
                conn.send(content.upper().encode('utf-8'))
                time.sleep(0.5)
            except ConnectionResetError:
                break

servers=socketserver.TreadingTcpServer(('127.0.0.1',9001),Myserver)
servers.serve_forever()
# import socket
# sk=socket.socket()
#
# sk.bind(('127.0.0.1',9001))
#
# sk.listen()
# while True:
#     conn,addr=sk.accept()
#     while True:
#         try:
#             content=conn.recv(1024).decode('utf-8')
#             conn.send(content.upper().encode('utf-8'))
#             time.sleep(0.5)
#         except ConnectionResetError:
#             break



























